import java.util.ArrayList;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 苏李涛
 * Date: 2024-09-26
 * Time: 0:47
 */

/**
 * 两个数组的交集:
 */
public class ArraySame {

    public ArrayList<Integer> intersection (ArrayList<Integer> nums1, ArrayList<Integer> nums2) {
        // write code here
        ArrayList<Integer> ret = new ArrayList<>();
        boolean[] hash = new boolean[1010];

        for(Integer x : nums1) {
            hash[x] = true;
        }

        for(Integer x : nums2) {
            if(hash[x] == true){
                ret.add(x);
                hash[x] = false;//处理重复元素：加入之后从原哈希表中删除
            }
        }

        return ret;
    }
}
